//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package 力扣.题库.未分类.demo1AND20;

public class demo8 {
    public demo8() {
    }

    public static void main(String[] args) {
        System.out.println(myAtoi("-91283472332"));
    }

    public static int myAtoi(String s) {
        long out = 0L;
        if (!s.isEmpty() && (s.length() != 1 || s.charAt(0) > '0' && s.charAt(0) <= '9')) {
            if (s.length() == 1 && s.charAt(0) >= '0' && s.charAt(0) <= '9') {
                return s.charAt(0) - 48;
            } else {
                int left = 0;
                int right = 0;

                while(s.charAt(left) == ' ') {
                    ++left;
                    if (left >= s.length()) {
                        return 0;
                    }
                }

                boolean flag = true;
                if (s.charAt(left) == '-') {
                    flag = false;
                    ++left;
                } else if (s.charAt(left) == '+') {
                    ++left;
                }

                while(s.charAt(left) == '0') {
                    ++left;
                    if (left >= s.length()) {
                        return 0;
                    }
                }

                for(int var6 = left; var6 < s.length() && s.charAt(var6) >= '0' && s.charAt(var6) <= '9'; ++var6) {
                    out = out * 10L + (long)(s.charAt(var6) - 48);
                    if (var6 - left >= 10) {
                        break;
                    }
                }

                if (!flag) {
                    out = -out;
                }

                if (out > 2147483647L) {
                    return Integer.MAX_VALUE;
                } else {
                    return out < -2147483648L ? Integer.MIN_VALUE : (int)out;
                }
            }
        } else {
            return 0;
        }
    }
}
